<form id="menuForm"  class="form-horizontal" method="post">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h5 class="blue">新增菜单</h5>
    </div>

    <div class="modal-body">
        <#if menu.parentId??>
        <!--显示父类 -->
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-4 no-padding-right" for="parentName">父类名:</label>
            <div class="">
                <div class="clearfix">
                    <input type="text" name="parentName" id="parentName" class="col-sm-8 " value="${menu.parentName!}" readonly/>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-4 no-padding-right" for="parentId">父类id:</label>
            <div class="">
                <div class="clearfix">
                    <input type="text" name="parentId" id="parentId" class="col-xs-12 col-sm-8" value="${menu.parentId!}" readonly/>
                </div>
            </div>
        </div>
        </#if>
        <input type="hidden" id="id" name="id" value="${menu.id!}">
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-4 no-padding-right" for="name">菜单名:</label>
            <div class="">
                <div class="clearfix">
                    <input type="text" name="name" id="name" class="col-sm-8 required" value="${menu.name!}"/>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-4 no-padding-right" for="flag">菜单标识(如:CategoryFlag):</label>
            <div class="">
                <div class="clearfix">
                    <input type="text" name="flag" id="flag" class=" col-sm-8 required" value="${menu.flag!}"/>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-4 no-padding-right" for="link">链接(外部链接请以http开头):</label>
            <div class="">
                <div class="clearfix">
                    <input type="text" name="link" id="link" class=" col-sm-8 " value="${menu.link!}"/>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-4 no-padding-right" for="sortIndex">排序号:</label>
            <div class=" ">
                <div class="clearfix">
                    <input type="text" name="sortIndex" id="sortIndex" class=" col-sm-8 required" value="${menu.sortIndex!}"/>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-4 no-padding-right" for="pcode">权限码:</label>
            <div class="">
                <div class="clearfix">
                    <input type="text" name="pcode" id="pcode" class=" col-sm-8 " value="${menu.pcode!}"/>
                </div>
            </div>
        </div>

        <!--<div class="form-group">-->
            <!--<label class="control-label col-xs-12 col-sm-4 no-padding-right" for="open">是否默认展开:</label>-->
            <!--<div class=" col-sm-8">-->
                <!--<div class="clearfix">-->
                    <!--<div>-->
                        <!--<select class="chosen-select form-control" name="open" id="open" data-placeholder="Choose a State...">-->
                            <!--<option value="0">否</option>-->
                            <!--<option value="1">是</option>-->
                        <!--</select>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
    <div class="modal-footer center">
        <button type="submit" class="btn btn-sm btn-success"><i class="ace-icon fa fa-check"></i> 保存</button>
        <button type="button" class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> 取消</button>
    </div>

</form>
<script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
<script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".date-picker").datepicker({
            language : 'zh-CN',
            autoclose: true,
            todayHighlight: true
        });

        $("#menuForm").validate({
            errorElement: 'div',
            errorClass: 'help-block',
            focusInvalid: true,
            highlight: function (e) {
                $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
            },
            success: function (e) {
                $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                $(e).remove();
            },
            errorPlacement: function (error, element) {
                if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                    var controls = element.closest('div[class*="col-"]');
                    if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
                    else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                }
                else if(element.is('.select2')) {
                    error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                }
                else if(element.is('.chosen-select')) {
                    error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                }
                else error.insertAfter(element.parent());
            },

            submitHandler: function (form) {
                $.ajax({
                    type: "POST",
                    url:"${ctx}/admin/menu/save.do",
                    data:$("#menuForm").serialize(),
                    dataType: 'text',
                    success: function(msg){
                        var msg = eval("("+msg+")");
                        if(msg.result == "success"){
                            window.location="${refer!}";
                        }else{
                            alert(msg.messages);
                        }
                    },
                    error: function(){
                        bootbox.alert("保存失败");
                    }
                });
            },
            invalidHandler: function (form) {
            }
        })

    });
</script>
